package android.slc.user.ui.dept.delegate

import android.slc.adapter.SelectBox
import android.slc.appbase.ui.utils.ItemDecorationUtils
import android.slc.appbase.ui.vd.BaseListPageVd
import android.slc.extras.user.entity.SysDept
import android.slc.user.ui.dept.adapter.DeptMultipleAdapter
import android.slc.user.ui.dept.vmbox.DeptListMultipleVmBox
import android.slc.user.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.checkbox.MaterialCheckBox

/**
 *
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/12/06 下午 2:55
 *
 */
class DeptListMultipleDelegate : BaseListPageVd<SelectBox<SysDept>, DeptListMultipleVmBox>() {
    override fun initSwipeRecycler() {
        super.initSwipeRecycler()
        ItemDecorationUtils.addItemDecorationByRecyclerView(swipeRecycler.recyclerView)
    }

    override fun getAdapter(list: MutableList<SelectBox<SysDept>>): BaseQuickAdapter<SelectBox<SysDept>, BaseViewHolder> {
        return DeptMultipleAdapter(list)
    }

    override fun initAdapterAndBaseEvent(): BaseQuickAdapter<SelectBox<SysDept>, BaseViewHolder> {
        return super.initAdapterAndBaseEvent().apply {
            setOnItemChildClickListener { adapter, view, position ->
                when (view.id) {
                    R.id.checkbox -> {
                        val selectBox: SelectBox<SysDept> =
                            adapter.getItem(position) as SelectBox<SysDept>
                        vmBox.select(position, selectBox)
                        (view as MaterialCheckBox).isChecked = selectBox.isChecked
                    }
                }
            }
        }
    }
}